using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GameManager : MonoBehaviour {
	
	public int winThreshold;
	
	private int robotsAlive;
	private int robotsSaved;

    public int RobotsAlive
    {
        get { return robotsAlive; }
    }

    public int RobotsSaved
    {
        get { return robotsSaved; }
    }

	// Use this for initialization
	void Awake () {
		RobotController[] robotsArray = GameManager.FindObjectsOfType(typeof(RobotController)) as RobotController[];
		
		robotsAlive = robotsArray.Length;
		
		robotsSaved = 0;
		
		if(winThreshold == 0) {
			winThreshold = 1;
		}
		
		// Debug.Log("There are " + robotsAlive.Length + " robots alive.");
	
	}
	
	// Update is called once per frame
	void Update () {
		
		if (Lost()) {
			//Lose();
		}
		else if (Won()) {
			Debug.Log("YOU WIN!?");
			//Win();
		}
	
	}
	
	
	public void robotKilled () {
		robotsAlive--;		
	}
	
	public void robotSaved () {
		robotsAlive--;
		robotsSaved++;
		Debug.Log("You rescued a robot!");
	}

    public bool Lost()
    {
        return (winThreshold > (robotsSaved + robotsAlive));

    }

    public bool Won()
    {
        return (robotsSaved >= winThreshold && robotsAlive <= 0);

    }


	
}
